import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:xiongan_app_yy/entrys/rp/inv_list_entity.dart';

class InTaskListWidget<T> extends StatefulWidget {
  final BuildContext context;
  final int index;
  final T data;
  final String type;

  InTaskListWidget(
      {this.context, this.index, this.data, this.type}); //@required data过几天记得加上

  @override
  State<StatefulWidget> createState() {
    return InTaskListWidgetState(index);
  }
}

class InTaskListWidgetState extends State<InTaskListWidget> {
  int i;

  InTaskListWidgetState(this.i);

  Widget stateWidget;

  @override
  Widget build(BuildContext context) {
    if ("入库任务" == widget.type) {
      if (widget.data.state == "未入库") {
        stateWidget = Text(
          "未入库",
          style: TextStyle(fontSize: 14.0, color: Color(0xFF00A5F1)),
        );
      } else if (widget.data.state == "已入库") {
        stateWidget = Text(
          "已入库",
          style: TextStyle(fontSize: 14.0, color: Color(0xFF2FC480)),
        );
      }else if (widget.data.state == "已驳回") {
        stateWidget = Text(
          "已驳回",
          style: TextStyle(fontSize: 14.0, color: Color(0xFFFF5555)),
        );
      }
    } else if ("出库任务" == widget.type) {
      if (widget.data.state == "未出库") {
        stateWidget = Text(
          "未出库",
          style: TextStyle(fontSize: 14.0, color: Color(0xFF00A5F1)),
        );
      } else if (widget.data.state == "已出库") {
        stateWidget = Text(
          "已出库",
          style: TextStyle(fontSize: 14.0, color: Color(0xFF2FC480)),
        );
      }else if (widget.data.state == "已驳回") {
        stateWidget = Text(
          "已驳回",
          style: TextStyle(fontSize: 14.0, color: Color(0xFFFF5555)),
        );
      }
    } else {
      if (widget.data.state == "未退货") {
        stateWidget = Text(
          "未退货",
          style: TextStyle(fontSize: 14.0, color: Color(0xFF00A5F1)),
        );
      } else if (widget.data.state == "已退货") {
        stateWidget = Text(
          "已退货",
          style: TextStyle(fontSize: 14.0, color: Color(0xFF2FC480)),
        );
      }else if (widget.data.state == "已驳回") {
        stateWidget = Text(
          "已驳回",
          style: TextStyle(fontSize: 14.0, color: Color(0xFFFF5555)),
        );
      }
    }

    return GestureDetector(
      child: Container(
        color: Colors.white,
        width: double.infinity,
        padding: EdgeInsets.all(10),
        margin: EdgeInsets.only(top: 10),
        child: Column(
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(bottom: 10),
              child: Row(
                children: <Widget>[
                  Expanded(
                      child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      RichText(
                        text: TextSpan(
                          text: widget.data.projectname,
                          style: TextStyle(
                              fontSize: 14.0, color: Color(0xff999999)),
                        ),
                      ),
                      RichText(
                        text: TextSpan(
                          text: '单号 :',
                          style: TextStyle(
                              fontSize: 14.0, color: Color(0xff999999)),
                          children: <TextSpan>[
                            TextSpan(
                              text: widget.type == "入库退货"
                                  ? widget.data.taskno
                                  : widget.data.taskno,
                              style: TextStyle(
                                  fontSize: 14.0, color: Color(0xFF00A5F1)),
                            ),
                          ],
                        ),
                      ),
                    ],
                  )),
                  Container(
                    child: Image.asset("assets/images/arrow.png",
                        fit: BoxFit.fill),
                    width: 8,
                    height: 13,
                  ),
                ],
              ),
            ),
            Divider(height: 1, color: Color(0xffdddddd)),
            Container(
                width: double.infinity,
                padding: EdgeInsets.only(top: 7),
                child: Row(
                  children: <Widget>[
                    Expanded(
                      child: stateWidget,
                    ),
                    Visibility(
                        visible: widget.data.applytime == null,
                        child: Text(
                          widget.data.applytime ?? "",
                          style: TextStyle(
                              fontSize: 14.0, color: Color(0xff999999)),
                        ))
                  ],
                ))
          ],
        ),
      ),
      onTap: () {
        if ("入库任务" == widget.type) {
          Navigator.pushNamed(context, "/in_task_details",
              arguments: widget.data.id);
        } else if ("出库任务" == widget.type) {
          Navigator.pushNamed(context, "/out_task_details",
              arguments: widget.data.id);
        } else {
          Navigator.pushNamed(context, "/warehousing_returns_details",
              arguments: widget.data.id);
        }
      },
    );
  }
}
